//
//  Bullet.m
//  MathMastersAsteroids
//
//  Created by Jordon Phillips on 3/7/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "Bullet.h"


@implementation Bullet

@synthesize dead,explode;

//initilizes the bullet to the proper starting values
-(void)initBullet:(float)newX:(float)newY{
	self.dead = FALSE;
	self.xPos = newX;
	self.yPos = newY;
	self.sprite = [[Sprite alloc] init];
	self.sprite.xPos = self.xPos;
	self.sprite.yPos = self.yPos;
	self.sprite.scale = 5;
	[self.sprite setDimensions:3];
	self.sprite.currentFrame=0;
	self.sprite.image = (13);
	animation = [NSTimer scheduledTimerWithTimeInterval:.05 target:self selector:@selector(animate) userInfo:nil repeats:YES];

}
//what the bullet does every iteration of the game loop
-(void)act{
	if(!self.dead){
		if(xPos<0){
			[self destroy];
			self.sprite.currentFrame=0;
			self.sprite.dead=TRUE;
		}else if(!self.dead){
			[self moveX: -3.5];
		}
	}
}
//changes the frame of the animation
-(void)animate{
	if(self.dead){
		self.sprite.currentFrame+=2;
		if(self.sprite.currentFrame>=10){
			self.sprite.currentFrame=0;
			self.sprite.dead=TRUE;
		}
	}else{
		self.sprite.currentFrame=0;
	}
	
}
//resets the bullet for reuse
-(void)reset:(float)newX:(float)newY{
	self.xPos = newX;
	self.yPos = newY;
	self.sprite.xPos = newX;
	self.sprite.yPos = newY;
	self.dead = FALSE;
	self.sprite.dead = FALSE;
	self.sprite.currentFrame=0;
}
//sets the bullet to dead
-(void)destroy{
	self.dead = TRUE;
}

-(void) dealloc{
	[animation release];
	[super dealloc];
}
@end
